// 校验方法
export var Validate = function(object) {
  var obj = object

  this.checkEffectiveDate = function(rule, value, callback) {
    console.log('checkEffectiveDate')
    if (value === null || value === '') {
      return callback()
    }
    if (!obj.rule.expirationDate) {
      return callback()
    }
    var effectiveDate = new Date(obj.rule.effectiveDate)
    var expirationDate = new Date(obj.rule.expirationDate)
    if (effectiveDate.getTime() > expirationDate.getTime()) {
      return callback(new Error('生效日期不能大于失效日期'))
    }
    return callback()
  }

  this.checkExpirationDate = function(rule, value, callback) {
    // console.log('checkExpirationDate')
    if (value === null || value === '') {
      return callback()
    }
    var effectiveDate = new Date(obj.rule.effectiveDate)
    var expirationDate = new Date(obj.rule.expirationDate)
    if (effectiveDate.getTime() > expirationDate.getTime()) {
      return callback(new Error('失效日期不能小于生效日期'))
    }
    return callback()
  }
}
